﻿#ifndef XAUDIO_H
#define XAUDIO_H

#include <memory>
#include <mutex>
#include <QtMultimedia/QAudioOutput>

namespace HeaderMedia {

class XAudio {
 public:
  static XAudio &getInstance() {
    static XAudio instance;
    return instance;
  }
  virtual ~XAudio() = default;

  void stop();
  void start();
  void volume(qreal value);
  void play(bool isPlayed);
  bool write(const char *data, int dataSize);
  int getFree();

  void setSampleRate(const int &rate) {
    xSampleRate = rate;
  }

  void setSampleSize(const int &size) {
    xSampleSize = size;
  }

  void setChannel(const int &channel) {
    xChannel = channel;
  }

 private:
  XAudio() = default;
  XAudio(const XAudio &) {}
  XAudio &operator=(const XAudio &) {}

  int xSampleRate = 48000;
  int xSampleSize = 16;
  int xChannel = 2;

  QAudioOutput *xAudioOutput;
  QIODevice *xIO;
  std::mutex xMtx;
};

} // namespace HeaderMedia

#endif // XAUDIO_H
